home *** CD-ROM | disk | FTP | other *** search
- /*
- * © Copyright 1995, Jano Banks, Paul Freeburn
- *
- * Name: PCIPeek.c
- * Authors: Jano Banks, Paul Freeburn.
- * Description: Peek and poke at PCI components in the system using MacOS system calls.
- *
- *
- * Revision History:
- * Date Initials Description
- * ---- -------- -----------
- * 5/26/95 jdb 1. Remade to fully use NameRegistry/Expansion Manager and get rid of
- * hardware-direct mode.
- * 2. Updated menus.
- * 3. Create way to use unit-address to select exact device.
- * 4. Took out CAPS-LOCK requirement
- *
- * Improvements planned
- * --------------------
- * 1. List PCI Devices
- * 2. Add full featured PCI Compliance Test (crdtst module).
- *
- */
-
- #pragma segment robix
-
- #include "PCIPeek.h"
-
-
- /************************************* Global Variables *********************************************/
- RegEntryID NodeID;
- Boolean NodeIDSelected;
- OSErr anErr;
- int InputBase = 16; // default to hex input
-
-
- char Command[8]; // allows for 8-character commands
- char arg1[132]; // allows for 132-character entry
- char arg2[132]; // allows for 132-character entry
- char arg3[132]; // allows for 132-character entry
- char arg4[132]; // allows for 132-character entry
-
-
-
-
-
- /************************************* Functions *********************************************/
- /* Fill in the help menu when you add a new command */
- void Help()
- {
- printf("--------------------------------------------------------------------\n");
- printf("DXY <addr> --> Display (Read) X=B/W/L/P, Y=C/I/M/T\r\n");
- printf("\tDBC < 8-bit hex addr> = Reads 8-bits from current node's Configuration Space\n");
- printf("\tDWC < 8-bit hex addr> = Reads 16-bits byte-reversed from current node's Configuration Space\n");
- printf("\tDLC < 8-bit hex addr> = Reads 32-bits byte-reversed from current node's Configuration Space\n");
- printf("\tDPC < 8-bit hex addr 8-bit page length> = Reads page 8-bits (default 128-bytes) from current node's Configuration Space\n");
- printf("\tDBI <32-bit hex addr> = Reads 8-bits from current node's IO Space\n");
- printf("\tDWI <32-bit hex addr> = Reads 16-bits byte-reversed from current node's IO Space\n");
- printf("\tDLI <32-bit hex addr> = Reads 32-bits byte-reversed from current node's IO Space\n");
- printf("\tDPI <32-bit hex addr 12-bit page length> = Reads page 8-bits (default 128-bytes) from current node's IO Space\n");
- printf("\tDBM <32-bit hex addr> = Reads 8-bits from any memory location\n");
- printf("\tDWM <32-bit hex addr> = Reads 16-bits byte-reversed from any memory location\n");
- printf("\tDLM <32-bit hex addr> = Reads 32-bits byte-reversed from any memory location\n");
- printf("\tDPM <32-bit hex addr 12-bit page length> = Reads page 8-bits (default 128-bytes) from any memory location\n");
-
- printf("\tDBT <no args> = Reads 8-bits from current node with an Interrupt Acknowledge Cycle\n");
- printf("\tDWT <no args> = Reads 16-bits byte-reversed from current node with an Interrupt Acknowledge Cycle\n");
- printf("\tDLT <no args> = Reads 32-bits byte-reversed from current node with an Interrupt Acknowledge Cycle\n");
- printf("\n");
-
- printf("SXY <addr data> --> Set (Write) X=B/W/L, Y=C/I/M/S/B\n");
- printf("\tSBC < 8-bit hex addr 8-bit hex data> = Writes 8-bits to current node's Configuration Space\n");
- printf("\tSWC < 8-bit hex addr 16-bit hex data> = Writes 16-bits byte-reversed to current node's Configuration Space\n");
- printf("\tSLC < 8-bit hex addr 32-bit hex data> = Writes 32-bits byte-reversed to current node's Configuration Space\n");
- printf("\tSBI <32-bit hex addr 8-bit hex data> = Writes 8-bits to current node's IO Space\n");
- printf("\tSWI <32-bit hex addr 16-bit hex data> = Writes 16-bits byte-reversed to current node's IO Space\n");
- printf("\tSLI <32-bit hex addr 32-bit hex data> = Writes 32-bits byte-reversed to current node's IO Space\n");
- printf("\tSBM <32-bit hex addr 8-bit hex data> = Writes 8-bits to any memory location\n");
- printf("\tSWM <32-bit hex addr 16-bit hex data> = Writes 16-bits byte-reversed to any memory location\n");
- printf("\tSLM <32-bit hex addr 32-bit hex data> = Writes 32-bits byte-reversed to any memory location\n");
- printf("\tSLS <32-bit hex data 32-bit hex data> = Writes 32-bits byte-reversed to PCIBus where current node lives with Special Cycle\n");
- printf("\tSLB <32-bit hex data 32-bit hex data> = Writes 32-bits byte-reversed to all PCIBuses in the system with Special Cycle\n");
- printf("\n");
-
- printf("C <no args> --> Displays current node's PCI Configuration Header (first 64 bytes of Configuration Space)\n");
- printf("\n");
-
- printf("N <no args> --> To select new node name\n");
- printf("\n");
-
- printf("? <no args> --> Prints this menu\n");
- printf("--------------------------------------------------------------------\n");
- printf("\n");
- }
-
-
- /*****************************************************
- function ProcessCommand_D
-
- ProcessCommand_D processes input string for
- DXY --> Display (Byte/Word/Long) to (Config/IO/Mem/IntAck)
- *****************************************************/
- void ProcessCommand_D(const int numOfArgs)
- {
-
- UInt32 Address;
- UInt32 Data;
- UInt8 TransLength;
- UInt8 TransType;
- UInt8 value8;
- UInt16 value16;
- UInt32 value32;
- UInt8 NoAddressCycle;
- UInt8 NoDataCycle;
-
- // char **unusedptr;
-
- TransLength = False; // 0
- TransType = False; // 0
- NoAddressCycle = False; //0
- NoDataCycle = False; //0
-
-
- switch (Command[1])
- {
- case 'B' :
- TransLength = lengthByte;
- break;
- case 'W' :
- TransLength = lengthWord;
- break;
- case 'L' :
- TransLength = lengthLongword;
- break;
- case 'P' :
- TransLength = lengthPage;
- break;
- }
-
- if (TransLength)
- {
- switch (Command[2])
- {
- case 'C' :
- TransType = typeConfig;
- break;
- case 'I' :
- TransType = typeIO;
- break;
- case 'M' :
- TransType = typeMemory;
- break;
- case 'T' :
- TransType = interruptAcknowledge;
- NoAddressCycle = True;
- break;
- }
-
- if (TransType)
- {
- if (numOfArgs > 1)
- {
- // Address = strtoul(arg1, unusedptr, InputBase);
- Address = strtoul(arg1, NULL, InputBase);
-
- if(numOfArgs > 2)
- Data = strtoul(arg2, NULL, InputBase);
- else
- Data = 128; /* default page to 128 bytes */
-
-
- switch (TransLength | TransType)
- {
- /* Config Read Cycles */
- case (lengthByte | typeConfig) :
- anErr = ExpMgrConfigReadByte(&NodeID, (LogicalAddress)Address, &value8);
- if (anErr == noErr)
- printf("%02X\n",value8);
- else
- printf("ERROR: Bad call to ExpMgrConfigReadByte. Error Code = %d\n", anErr);
- break;
-
- case (lengthWord | typeConfig) :
- anErr = ExpMgrConfigReadWord(&NodeID, (LogicalAddress)Address, &value16);
- if (anErr == noErr)
- printf("%04X\n",value16);
- else
- printf("ERROR: Bad call to ExpMgrConfigReadWord. Error Code = %d\n", anErr);
- break;
-
- case (lengthLongword | typeConfig) :
- anErr = ExpMgrConfigReadLong(&NodeID, (LogicalAddress)Address, &value32);
- if (anErr == noErr)
- printf("%08X\n",value32);
- else
- printf("ERROR: Bad call to ExpMgrConfigReadLong. Error Code = %d\n", anErr);
- break;
-
- case (lengthPage | typeConfig) :
- if(Data > 256)
- Data = 256;
- if(Address > 256)
- Address = 0; /* limit config dispaly to 256 bytes */
- printf("\n");
- printf("Displaying Configuration Space from %02X\n",Address);
- DisplayMemoryIOConfig(Address, Data, TransType); /* display page(s) of memory, I/O, or Config space */
- break;
-
-
- /* IO Read Cycles */
- case (lengthByte | typeIO) :
- anErr = ExpMgrIOReadByte(&NodeID, (LogicalAddress)Address, &value8);
- if (anErr == noErr)
- printf("%02X\n",value8);
- else
- printf("ERROR: Bad call to ExpMgrIOReadByte. Error Code = %d\n", anErr);
- break;
-
- case (lengthWord | typeIO) :
- anErr = ExpMgrIOReadWord(&NodeID, (LogicalAddress)Address, &value16);
- if (anErr == noErr)
- printf("%04X\n",value16);
- else
- printf("ERROR: Bad call to ExpMgrIOReadWord. Error Code = %d\n", anErr);
- break;
-
- case (lengthLongword | typeIO) :
- anErr = ExpMgrIOReadLong(&NodeID, (LogicalAddress)Address, &value32);
- if (anErr == noErr)
- printf("%08X\n",value32);
- else
- printf("ERROR: Bad call to ExpMgrIOReadLong. Error Code = %d\n", anErr);
- break;
-
- case (lengthPage | typeIO) :
- printf("\n");
- printf("Displaying IO Space from %02X\n",Address);
- DisplayMemoryIOConfig(Address, Data, TransType); /* display page(s) of memory, I/O, or Config space */
- break;
-
-
- /* Memory Read Cycles */
- case (lengthByte | typeMemory) :
- value8 = *(volatile UInt8 *)Address;
- printf("%02X\n",value8);
- break;
-
- case (lengthWord | typeMemory) :
- value16 = *(volatile UInt16 *)Address;
- printf("%04X\n",EndianSwap16Bit(value16));
- break;
-
- case (lengthLongword | typeMemory) :
- value32 = *(volatile UInt32 *)Address;
- printf("%08X\n",EndianSwap32Bit(value32));
- break;
-
- case (lengthPage | typeMemory) :
- printf("\n");
- printf("Displaying Memory Space from %02X\n",Address);
- DisplayMemoryIOConfig(Address, Data, TransType); /* display page(s) of memory, I/O, or Config space */
- break;
- }
- }
- else /* No address for an interrupt acknowledge cycle */
- {
- switch (TransLength | TransType)
- {
- /* Interrupt Acknowledge Read Cycles */
- case (lengthByte | interruptAcknowledge) :
- anErr = ExpMgrInterruptAcknowledgeReadByte(&NodeID, &value8);
- if (anErr == noErr)
- printf("%02X\n",value8);
- else
- printf("ERROR: Bad call to ExpMgrInterruptAcknowledgeReadByte. Error Code = %d\n", anErr);
- break;
-
- case (lengthWord | interruptAcknowledge) :
- anErr = ExpMgrInterruptAcknowledgeReadWord(&NodeID, &value16);
- if (anErr == noErr)
- printf("%04X\n",value16);
- else
- printf("ERROR: Bad call to ExpMgrInterruptAcknowledgeReadWord. Error Code = %d\n", anErr);
- break;
-
- case (lengthLongword | interruptAcknowledge) :
- anErr = ExpMgrInterruptAcknowledgeReadLong(&NodeID, &value32);
- if (anErr == noErr)
- printf("%08X\n",value32);
- else
- printf("ERROR: Bad call to ExpMgrInterruptAcknowledgeReadLong. Error Code = %d\n", anErr);
- }
-
- if (!NoAddressCycle)
- printf("No address entered. No action performed.\n");
- }
- }
- else
- {
- printf("Invalid Transfer Type (C/I/M/T valid). No action performed.\n");
- }
- }
- else
- {
- printf("Invalid Transfer Length (B/W/L valid). No action performed.\n");
- }
- }
-
-
- /*****************************************************
- function DisplayMemoryIOConfig
-
- Displays memory, I/O, and or Config space starting @ StartAddress
- and for DisplayLength bytes, or a Page of 128 bytes.
- *****************************************************/
- void DisplayMemoryIOConfig(UInt32 StartAddress, UInt32 DisplayLength, UInt8 CycleType)
- {
-
- UInt32 TempAddress;
- UInt8 InputPage[32];
- UInt8 num8;
- int cntByte;
- int j;
- int k;
-
- if(DisplayLength > 4096)
- DisplayLength = 4096; /* set maximum length to 4K */
- if(DisplayLength < 16)
- DisplayLength = DisplayLength + 16;
-
-
- for(DisplayLength = DisplayLength/16; DisplayLength > 0; DisplayLength--)
- {
- TempAddress = StartAddress;
- j = 0;
-
-
- switch (CycleType)
- {
- case typeMemory :
-
- while (j < 16)
- {
- InputPage[j] = *(volatile UInt8 *)StartAddress++; /* read a line (16 bytes) of memory space */
- j++;
- }
- break;
-
- case typeIO :
-
- while (j < 16)
- {
- anErr = ExpMgrIOReadByte(&NodeID, (LogicalAddress)StartAddress++, &num8); /* read a line (16 bytes) of I/O space */
- if (anErr == noErr)
- {
- InputPage[j] = num8;
- j++;
- }
-
- else
- {
- printf("\n");
- printf("ERROR: Bad call to ExpMgrIOReadByte. Error Code = %d\n", anErr);
- j = 16; /* set loop indexes to done */
- DisplayLength = 0;
- }
- }
- break;
-
- case typeConfig :
-
- while (j < 16)
- {
- anErr = ExpMgrConfigReadByte(&NodeID, (LogicalAddress)StartAddress++, &num8); /* read a line (16 bytes) of config space */
- if (anErr == noErr)
- {
- InputPage[j] = num8;
- j++;
- }
-
- else
- {
- printf("\n");
- printf("ERROR: Bad call to ExpMgrConfigReadByte. Error Code = %d\n", anErr);
- j = 16; /* set loop indexes to done */
- DisplayLength = 0;
- }
- }
- break;
- }
-
- StartAddress = TempAddress;
- j = 0;
- k = 0;
- printf("%02X ",StartAddress);
- cntByte = 0;
-
- while (cntByte < 8) /* display 16 Bytes in Hex */
- {
- printf("%02X", InputPage[j]);
- j++;
- StartAddress++;
- printf("%02X", InputPage[j]);
- j++;
- StartAddress++;
- printf(" ");
- cntByte++;
- }
-
- printf(" ");
- cntByte = 0;
-
- while (cntByte < 16) /* display ascii equivalent */
- {
- if(InputPage[k] <= 0X20 || InputPage[k] >= 0XD9)
- InputPage[k] = 0X2E;
-
- printf("%c", InputPage[k]);
- k++;
- cntByte++;
- }
-
- printf("\n");
- }
- }
-
-
-
-
- /*****************************************************
- function ProcessCommand_S
-
- ProcessCommand_S processes input string for
- SXY --> Set (Byte/Word/Long) to (Config/IO/Mem/Spec/SpecBroadcast)
- *****************************************************/
- void ProcessCommand_S(const int numOfArgs)
- {
-
- UInt32 Address;
- UInt32 Data;
- UInt8 TransLength;
- UInt8 TransType;
- UInt8 NoDataCycle;
- // char **unusedptr;
-
- TransLength = False;
- TransType = False;
- NoDataCycle = False;
-
-
- switch (Command[1])
- {
- case 'B' :
- TransLength = lengthByte;
- break;
- case 'W' :
- TransLength = lengthWord;
- break;
- case 'L' :
- TransLength = lengthLongword;
- break;
- }
-
- if (TransLength)
- {
- switch (Command[2])
- {
- case 'C' :
- TransType = typeConfig;
- break;
- case 'I' :
- TransType = typeIO;
- break;
- case 'M' :
- TransType = typeMemory;
- break;
- case 'S' :
- TransType = typeSpecialWrite;
- NoDataCycle = True;
- break;
- case 'B' :
- TransType = typeSpecialBroadcast;
- NoDataCycle = True;
- break;
-
- }
-
- if (TransType)
- {
- if (numOfArgs > 1)
- {
- // Address = strtoul(arg1, unusedptr, InputBase);
- Address = strtoul(arg1, NULL, InputBase);
-
- if (numOfArgs > 2)
- {
- // Data = strtoul(arg2, unusedptr, InputBase);
- Data = strtoul(arg2, NULL, InputBase);
-
- switch (TransLength | TransType)
- {
-
- /* Config Write Cycles */
- case (lengthByte | typeConfig) :
- anErr = ExpMgrConfigWriteByte(&NodeID, (LogicalAddress)Address, (UInt8)Data);
- if (anErr != noErr)
- printf("ERROR: Bad call to ExpMgrConfigWriteByte. Error Code = %d\n", anErr);
- break;
-
- case (lengthWord | typeConfig) :
- anErr = ExpMgrConfigWriteWord(&NodeID, (LogicalAddress)Address, (UInt16)Data);
- if (anErr != noErr)
- printf("ERROR: Bad call to ExpMgrConfigWriteWord. Error Code = %d\n", anErr);
- break;
-
- case (lengthLongword | typeConfig) :
- anErr = ExpMgrConfigWriteLong(&NodeID, (LogicalAddress)Address, Data);
- if (anErr != noErr)
- printf("ERROR: Bad call to ExpMgrConfigWriteLong. Error Code = %d\n", anErr);
- break;
-
- /* IO Write Cycles */
- case (lengthByte | typeIO) :
- anErr = ExpMgrIOWriteByte(&NodeID, (LogicalAddress)Address, (UInt8)Data);
- if (anErr != noErr)
- printf("ERROR: Bad call to ExpMgrIOWriteByte. Error Code = %d\n", anErr);
- break;
-
- case (lengthWord | typeIO) :
- anErr = ExpMgrIOWriteWord(&NodeID, (LogicalAddress)Address, (UInt16)Data);
- if (anErr != noErr)
- printf("ERROR: Bad call to ExpMgrIOWriteWord. Error Code = %d\n", anErr);
- break;
-
- case (lengthLongword | typeIO) :
- anErr = ExpMgrIOWriteLong(&NodeID, (LogicalAddress)Address, Data);
- if (anErr != noErr)
- printf("ERROR: Bad call to ExpMgrIOWriteLong. Error Code = %d\n", anErr);
- break;
-
- /* Memory Write Cycles */
- case (lengthByte | typeMemory) :
- *(volatile UInt8 *)Address = (UInt8)Data;
- break;
- case (lengthWord | typeMemory) :
- *(volatile UInt16 *)Address = EndianSwap16Bit((UInt16)Data);
- break;
- case (lengthLongword | typeMemory) :
- *(volatile UInt32 *)Address = EndianSwap32Bit(Data);
- break;
-
-
- }
- }
- else /* no 2nd argument for Special Cycles */
- {
-
- switch (TransLength | TransType)
- {
- case (lengthLongword | typeSpecialWrite) :
- anErr = ExpMgrSpecialCycleWriteLong(&NodeID, Address); /* Address is really data, but Address variable saved first above */
- if (anErr != noErr)
- printf("ERROR: Bad call to ExpMgrSpecialCycleWriteLong. Error Code = %d\n", anErr);
- break;
-
- case (lengthLongword | typeSpecialBroadcast) :
- anErr = ExpMgrSpecialCycleBroadcastLong(Address);
- if (anErr != noErr)
- printf("ERROR: Bad call to ExpMgrSpecialCycleBroadcastLong. Error Code = %d\n", anErr);
- break;
- }
- if(!NoDataCycle) /* This means no 2nd Arg for other write transactions */
- printf("No data entered. No action performed.\n");
- }
- }
- else
- {
- if(!NoDataCycle)
- printf("No address entered. No action performed.\n"); /* for non Special Cycle checking */
- else
- printf("No data entered. No action performed.\n"); /* for Special Cycle checking */
- }
- }
- else
- {
- printf("Invalid Transfer Type (C/I/M/S/B valid). No action performed.\n");
- }
- }
- else
- {
- printf("Invalid Transfer Length (B/W/L valid). No action performed.\n");
- }
- }
-
-
- // ------------------------------------------------
- // FindPropertyWithValue
- // Find a node with a specific property and value in the Registry
- // jdb: propertyNamePtr is the string to match
- // propertyValue is the value of the property
- // foundEntry is the returned node id.
- // returns: 1. noErr if foundEntry is updated
- // 2. done if done is true (got to end of device tree and didn't find property)
- // 3. an error if Registry routines return an error.
- // ------------------------------------------------
- OSStatus FindPropertyWithValue(const RegPropertyName *propertyName, const void *propertyValue, const RegPropertyValueSize propertySize, RegEntryID *foundEntry)
- {
- RegEntryIter cookie;
- RegEntryID theEntry;
- RegEntryIterationOp iterOp;
- Boolean done;
- OSStatus err = noErr;
- /*
- RegPropertyValueSize tempSize;
- RegPropertyValueSize tempSize2;
- RegPropertyName *temppropertyNamePtr;
- RegPropertyName temppropertyName;
- RegCStrEntryName *tempCharPtr;
- */
- RegistryEntryIDInit(&theEntry);
-
- err = RegistryEntryIterateCreate(&cookie);
- if (err != noErr)
- return err;
-
- iterOp = kRegIterContinue;
- /*
- tempSize = sizeof("Big_Bird");
- tempSize2 = sizeof(0x81000000);
- temppropertyNamePtr = propertyName;
- temppropertyName = *propertyName;
- tempCharPtr = (RegCStrEntryName *) propertyValue;
- */
- err = RegistryEntrySearch(&cookie, iterOp, &theEntry, &done,
- propertyName, propertyValue, propertySize);
-
- if (!done && (err == noErr))
- {
- *foundEntry = theEntry;
- }
- else if (done)
- err = done;
-
- RegistryEntryIDDispose(&theEntry);
- RegistryEntryIterateDispose(&cookie);
-
- return err;
- }
-
-
- OSStatus FindNameWithUnitAddr(const void *nodeNameValue, const RegPropertyValueSize nodeNameSize, const UInt32 unitAddr, RegEntryID *foundEntry)
- {
- RegEntryIter cookie;
- RegEntryID theEntry;
- RegEntryIterationOp iterOp;
- Boolean done;
- OSStatus err = noErr;
-
- RegPropertyValueSize SizeOfReg;
- void *regValue;
- UInt32 *ThisUnitAddr;
-
- #define SizeOfunitAddr 4;
-
- RegistryEntryIDInit(&theEntry);
-
- err = RegistryEntryIterateCreate(&cookie);
- if (err != noErr)
- return err;
-
- iterOp = kRegIterContinue;
-
- do
- {
- err = RegistryEntrySearch(&cookie, iterOp, &theEntry, &done,
- "name", nodeNameValue, nodeNameSize);
-
- if (!done && (err == noErr)) /* we found a name match, now let's check if unit addr matches */
- {
- err = RegistryPropertyGetSize(&theEntry, "reg", &SizeOfReg); /* need this node's reg property size */
- if (err != noErr)
- return err;
-
- regValue = NULL; /* allocate space for a local variable */
- regValue = NewPtr(SizeOfReg); /* in Memory.h */
- if (regValue == NULL)
- {
- printf("ERROR: No memory available to store property value.\n");
- return ERR_MEMALLOC;
- }
-
- err = RegistryPropertyGet(&theEntry, "reg", regValue, &SizeOfReg); /* get the reg value */
- if (err != noErr)
- return err;
-
- ThisUnitAddr = regValue; /* pointer now to a UInt32 */
-
- if (*ThisUnitAddr == unitAddr) /* if it matches, fill in return value */
- *foundEntry = theEntry;
- }
- } while (!done && (err == noErr) && (*ThisUnitAddr != unitAddr)); /* otherwise, keep going */
-
- if (done)
- err = done; /* if we got through the whole Name Registry without a match, that's an error */
- RegistryEntryIDDispose(&theEntry);
- RegistryEntryIterateDispose(&cookie);
-
- return err;
- }
-
-
-
- OSStatus MessageDeviceUnderTest(const RegEntryID *theEntry)
- {
- OSStatus err;
- RegPropertyValueSize SizeOfProp;
- void *propValue;
- UInt32 *unitAddr;
- PCIUnitAddressPtr unitAddrParts;
- PCIBusNumber theBusNumber;
- PCIDeviceFunction theDeviceAndFunction;
-
- /* print statement */
- printf("Current node info:\n");
-
- /* first get the name of the node */
- printf("\tName:\t\t\t");
- err = RegistryPropertyGetSize(theEntry, "name", &SizeOfProp); /* need node's name property size */
- if (err == noErr)
- {
- propValue = NULL; /* allocate space for a local variable */
- propValue = NewPtr(SizeOfProp); /* in Memory.h */
- if (propValue == NULL)
- {
- printf("\nERROR: No memory available to store property value.\n");
- return ERR_MEMALLOC;
- }
-
- err = RegistryPropertyGet(theEntry, "name", propValue, &SizeOfProp); /* get the name value */
- if (err != noErr)
- return err;
-
- /* print name */
- printf("%s\n",(char *) propValue);
- }
- else /* no name? Must be first time through (no node yet) */
- printf("Unknown\n");
-
- /* now get the AAPL,slot-name */
- printf("\tSlot:\t\t\t");
- err = RegistryPropertyGetSize(theEntry, "AAPL,slot-name", &SizeOfProp); /* need node's AAPL,slot-name property size */
- if (err == noErr)
- {
- propValue = NULL; /* allocate space for a local variable */
- propValue = NewPtr(SizeOfProp); /* in Memory.h */
- if (propValue == NULL)
- {
- printf("\nERROR: No memory available to store property value.\n");
- return ERR_MEMALLOC;
- }
- err = RegistryPropertyGet(theEntry, "AAPL,slot-name", propValue, &SizeOfProp); /* get the name value */
- if (err != noErr)
- return err;
- /* print AAPL,slot-name */
- printf("%s\n",(char *) propValue);
- }
- else if (err == nrNotFoundErr) /* some PCI devices are on the motherboard */
- printf("Motherboard device\n");
- else /* other errors occur if first time through (no node yet) */
- printf("Unknown\n");
-
- /* now get the unit-address portion of the reg property */
- printf("\tUnit-Address:\t");
- err = RegistryPropertyGetSize(theEntry, "reg", &SizeOfProp); /* need node's reg property size */
- if (err == noErr)
- {
- propValue = NULL; /* allocate space for a local variable */
- propValue = NewPtr(SizeOfProp); /* in Memory.h */
- if (propValue == NULL)
- {
- printf("\nERROR: No memory available to store property value.\n");
- return ERR_MEMALLOC;
- }
- err = RegistryPropertyGet(theEntry, "reg", propValue, &SizeOfProp); /* get the name value */
- if (err != noErr)
- return err;
-
- unitAddr = propValue; /* pointer to Full number */
- unitAddrParts = propValue; /* pointer to same, but with parts breakdown */
- printf("%X\n", *unitAddr);
-
- theBusNumber = unitAddrParts->busNumber;
- theDeviceAndFunction = unitAddrParts->deviceFunctionNumber;
- printf("\t\tBus Number:\t\t\t%2X\n",theBusNumber);
- printf("\t\tDevice Number:\t\t%2X\n",((theDeviceAndFunction>>3) & kPCIDeviceNumberMask));
- printf("\t\tFunction Number:\t%2X\n",(theDeviceAndFunction & kPCIFunctionNumberMask));
- }
- else /* no reg(unit-address)? Could be at initialization time (no node yet) or FCode hosed */
- printf("Unknown\n");
-
- return err;
- }
-
-
- OSStatus DisplayConfiguration(const RegEntryID *theEntry)
- {
- OSStatus err;
- UInt8 ConfigHeader[64];
- int i;
-
- err = noErr;
- i = 0;
- while ((err == noErr) & (i < 64))
- {
- err = ExpMgrConfigReadByte((RegEntryIDPtr)theEntry, (LogicalAddress)i, &ConfigHeader[i]);
- i++;
- }
- if (err != noErr)
- {
- printf("ERROR: Bad call to ExpMgrConfigReadByte. Error Code = %d\n", err);
- return err;
- }
-
- /* common to all PCI Devices (first 16 bytes) */
- printf("Vendor ID = %02X%02X | 0x00\n", ConfigHeader[0x01],ConfigHeader[0x00]);
- printf("Device ID = %02X%02X | 0x02\n", ConfigHeader[0x03],ConfigHeader[0x02]);
- printf("Command = %02X%02X | 0x04\n", ConfigHeader[0x05],ConfigHeader[0x04]);
- printf("Status = %02X%02X | 0x06\n", ConfigHeader[0x07],ConfigHeader[0x06]);
- printf("Revision ID = %02X | 0x08\n",ConfigHeader[0x08]);
- printf("Class Code = %02X%02X%02X | 0x09\n", ConfigHeader[0x0B],ConfigHeader[0x0A],ConfigHeader[0x09]);
- printf("Cache line size = %02X | 0x0C\n",ConfigHeader[0x0C]);
- printf("Latency = %02X | 0x0D\n",ConfigHeader[0x0D]);
- printf("Header type = %02X | 0x0E\n",ConfigHeader[0x0E]);
- printf("BIST = %02X | 0x0F\n",ConfigHeader[0x0F]);
-
- /* rest of standard header */
- if ((ConfigHeader[0xE] & 0x01) == 0x00)
- {
- printf("Base addr 0 = %02X%02X%02X%02X | 0x10\n", ConfigHeader[0x13],ConfigHeader[0x12],ConfigHeader[0x11],ConfigHeader[0x10]);
- printf("Base addr 1 = %02X%02X%02X%02X | 0x14\n", ConfigHeader[0x17],ConfigHeader[0x16],ConfigHeader[0x15],ConfigHeader[0x14]);
- printf("Base addr 2 = %02X%02X%02X%02X | 0x18\n", ConfigHeader[0x1B],ConfigHeader[0x1A],ConfigHeader[0x19],ConfigHeader[0x18]);
- printf("Base addr 3 = %02X%02X%02X%02X | 0x1C\n", ConfigHeader[0x1F],ConfigHeader[0x1E],ConfigHeader[0x1D],ConfigHeader[0x1C]);
- printf("Base addr 4 = %02X%02X%02X%02X | 0x20\n", ConfigHeader[0x23],ConfigHeader[0x22],ConfigHeader[0x21],ConfigHeader[0x20]);
- printf("Base addr 5 = %02X%02X%02X%02X | 0x24\n", ConfigHeader[0x27],ConfigHeader[0x26],ConfigHeader[0x25],ConfigHeader[0x24]);
- printf("Cardbus CIS Ptr = %02X%02X%02X%02X | 0x28\n", ConfigHeader[0x2B],ConfigHeader[0x2A],ConfigHeader[0x29],ConfigHeader[0x28]);
- printf("Subsys Vendor ID = %02X%02X | 0x2C\n", ConfigHeader[0x2D],ConfigHeader[0x2C]);
- printf("Subsys ID = %02X%02X | 0x2E\n", ConfigHeader[0x2F],ConfigHeader[0x2E]);
- printf("ROM base = %02X%02X%02X%02X | 0x30\n", ConfigHeader[0x33],ConfigHeader[0x32],ConfigHeader[0x31],ConfigHeader[0x30]);
- printf("Reserved = %02X%02X%02X%02X | 0x34\n", ConfigHeader[0x37],ConfigHeader[0x36],ConfigHeader[0x35],ConfigHeader[0x34]);
- printf("Reserved = %02X%02X%02X%02X | 0x38\n", ConfigHeader[0x3B],ConfigHeader[0x3A],ConfigHeader[0x39],ConfigHeader[0x38]);
- printf("Interrupt line = %02X | 0x3C\n",ConfigHeader[0x3C]);
- printf("Interrupt pin = %02X | 0x3D\n",ConfigHeader[0x3D]);
- printf("Min_Gnt = %02X | 0x3E\n",ConfigHeader[0x3E]);
- printf("Max_Lat = %02X | 0x3F\n",ConfigHeader[0x3F]);
- }
-
- /* rest of PCI 2 PCI header */
- else if ((ConfigHeader[0xE] & 0x01) == 0x01)
- {
- printf("Base addr 0 = %02X%02X%02X%02X | 0x10\n", ConfigHeader[0x13],ConfigHeader[0x12],ConfigHeader[0x11],ConfigHeader[0x10]);
- printf("Base addr 1 = %02X%02X%02X%02X | 0x14\n", ConfigHeader[0x17],ConfigHeader[0x16],ConfigHeader[0x15],ConfigHeader[0x14]);
- printf("Primary Bus # = %02X | 0x18\n",ConfigHeader[0x18]);
- printf("2ndary Bus # = %02X | 0x19\n",ConfigHeader[0x19]);
- printf("Subordinate Bus# = %02X | 0x1A\n",ConfigHeader[0x1A]);
- printf("2ndary Lat Timer = %02X | 0x1B\n",ConfigHeader[0x1B]);
- printf("IO Base = %02X | 0x1C\n",ConfigHeader[0x1C]);
- printf("IO Limit = %02X | 0x1D\n",ConfigHeader[0x1D]);
- printf("2ndary Status = %02X%02X | 0x1E\n", ConfigHeader[0x1F],ConfigHeader[0x1E]);
- printf("Memory Base = %02X%02X | 0x20\n", ConfigHeader[0x21],ConfigHeader[0x20]);
- printf("Memory Limit = %02X%02X | 0x22\n", ConfigHeader[0x23],ConfigHeader[0x22]);
- printf("Prefetch Mem Base= %02X%02X | 0x24\n", ConfigHeader[0x25],ConfigHeader[0x24]);
- printf("Prefetch Mem Lim = %02X%02X | 0x26\n", ConfigHeader[0x27],ConfigHeader[0x26]);
- printf("Pftch Base Upr 32= %02X%02X%02X%02X | 0x28\n", ConfigHeader[0x2B],ConfigHeader[0x2A],ConfigHeader[0x29],ConfigHeader[0x28]);
- printf("Pftch Lim Upr 32= %02X%02X%02X%02X | 0x2C\n", ConfigHeader[0x2F],ConfigHeader[0x2E],ConfigHeader[0x2D],ConfigHeader[0x2C]);
- printf("IO Base Upper 16 = %02X%02X | 0x30\n", ConfigHeader[0x31],ConfigHeader[0x30]);
- printf("IO Lim Upper 16 = %02X%02X | 0x32\n", ConfigHeader[0x33],ConfigHeader[0x32]);
- printf("Reserved = %02X%02X%02X%02X | 0x34\n", ConfigHeader[0x37],ConfigHeader[0x36],ConfigHeader[0x35],ConfigHeader[0x34]);
- printf("ROM base = %02X%02X%02X%02X | 0x38\n", ConfigHeader[0x3B],ConfigHeader[0x3A],ConfigHeader[0x39],ConfigHeader[0x38]);
- printf("Interrupt line = %02X | 0x3C\n",ConfigHeader[0x3C]);
- printf("Interrupt pin = %02X | 0x3D\n",ConfigHeader[0x3D]);
- printf("Bridge Control = %02X%02X | 0x3E\n", ConfigHeader[0x3F],ConfigHeader[0x3E]);
- }
-
- /* rest of unknown header */
- else
- {
- printf("!! Unknown Header Type !! Listing below is just addresses and longword data,ConfigHeader\n");
- for (i = 16; i < 64; i=i+4)
- {
- printf(" = %02X%02X%02X%02X | 0x%02X\n",ConfigHeader[i+3],ConfigHeader[i+2],ConfigHeader[i+1],ConfigHeader[i],i);
- }
- }
- return err;
-
- }
-
-
- void GetNodeName()
- {
- UInt32 unitAddr;
- int numOfArgs;
- OSErr err;
- Boolean Done;
- char InNameNode[132];
- char nodeName[132];
-
- Done = FALSE;
- while (!Done)
- {
- printf("Enter new node name =>");
- gets(InNameNode);
- if(strcmp(InNameNode, "") == 0) /* if nothing entered */
- {
- if (NodeIDSelected == FALSE)
- printf("\tNo node selected yet.\n");
- else
- {
- printf("\tNo Change.\n");
- Done = TRUE;
- }
- }
- else
- {
- numOfArgs = sscanf(InNameNode, "%s %x", nodeName, &unitAddr);
- if (numOfArgs == 1) /* they're just matching name */
- {
- err = FindPropertyWithValue("name", nodeName, strlen(nodeName)+1, &NodeID);
- }
- if (numOfArgs == 2) /* they're trying to get a node ID from a name and unit address */
- {
- err = FindNameWithUnitAddr(nodeName, strlen(nodeName)+1, unitAddr, &NodeID);
- }
-
- if(err != noErr)
- {
- printf("Device node %s is not in the device tree\n", InNameNode);
- }
- else
- Done = TRUE;
- }
- }
- err = MessageDeviceUnderTest(&NodeID);
-
- }
-
- void ToUpperString(Ptr theString)
- {
- short lengthOfString ;
-
- lengthOfString = strlen((char *)theString);
- UpperText(theString, lengthOfString); /* from TextUtils.h */
- }
-
- /************************************* Main Loop ********************************************/
-
- void main()
- {
- UInt8 Exit;
- int numOfArgs;
- char CommandLine[132];
-
- Exit = False;
- NodeIDSelected = FALSE;
-
- printf("***** PCIPeek 2.1 6/95, Let's you peek and poke your PCI devices! *****\n\n");
- printf("\tOriginated by: Rob Glanville, Jano Banks, Mike Regal, and Al Scalise\n");
- printf("\tModified by: Jano Banks and Paul Freeburn\n\n");
-
- Help(); // print the menu
- GetNodeName(); // get the initial Node Name
- NodeIDSelected = TRUE; // can't get out of GetNodeName unless it is!
-
-
- while (!Exit)
- {
-
- printf(">");
- gets(CommandLine);
- numOfArgs = sscanf(CommandLine, "%s %s %s %s %s", Command, arg1, arg2, arg3, arg4);
- switch (numOfArgs)
- {
- case 5: ToUpperString((Ptr)arg4);
- case 4: ToUpperString((Ptr)arg3);
- case 3: ToUpperString((Ptr)arg2);
- case 2: ToUpperString((Ptr)arg1);
- case 1: ToUpperString((Ptr)Command);
- }
-
- switch(Command[0])
- {
- case '?' :
- Help();
- break;
- case 'N' :
- GetNodeName();
- break;
- case 'C' :
- DisplayConfiguration(&NodeID);
- break;
- case 'D' :
- ProcessCommand_D(numOfArgs);
- break;
- case 'S' :
- ProcessCommand_S(numOfArgs);
- break;
- default :
- printf("Unknown command\n");
- break;
- }
- }
- }
-
-
-